<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Partners_Model extends CI_Model{
    function __construct()
    {
        parent::__construct();
    }
    function getAllData($num,$offset){
        $query = $this->db->get('partners',$num,$offset);
      
        return $query->result();  
    } 
     function get_object($id)
    {
        $query = $this->db->get_where('partners', array('partners_id' =>$id));
        return $query->row();
    }
    function getNumData(){
        $query = $this->db->get('partners');
        return $query->num_rows();
    }
    function delete($id){
          $this->db->where('partners_id',$id);
          $query = $this->db->delete('partners');
          if($query){
              return true;
          }else{
              return false;
          }
    }
	function deleted($id){
          $this->db->where('partners_id',$id);
		  $data=array('bl_active'=>'-1');
          $query = $this->db->update('partners',$data);
          if($query){
              return true;
          }else{
              return false;
          }
    }
    function get_list_permit(){
        return $this->db->get('permission')->result();
    }
   
   function saveData($partners_id,$data){
             if($partners_id!=0){
                    $this->db->where('partners_id',$partners_id);
                    if($this->db->update('partners',$data)){
                         return true;
                    }else{
                         return false;
                    }
             }else{
                    if($this->db->insert('partners',$data)){
                        return true;
                        
                    }else{
                        return false;
                    }
            }
    }
    function get_num_data($arr_search){
            /*Begin search*/
            switch($arr_search['field_search'])
            {
                    case 'name':
                            $this->db->like('name',$arr_search['key_search']);
                            break ;
					
                    
            }
            /*End search*/
			
            $query = $this->db->get('partners');
             return $query->num_rows();
    }
    function get_all_data($num,$offset,$arr_search)
    {
           $this->db->select('partners.*');
		    /*Begin search*/
            switch($arr_search['field_search'])
            {
					
					case 'name':
                            $this->db->like('name',$arr_search['key_search']);
                            break ;
                    
            }
            /*End search*/
            $this->db->where('partners.bl_active <>',-1);
            $this->db->order_by('nb_order','ASC');
            $query = $this->db->get('partners',$num,$offset);
             return $query->result();
    }
   
	   function optionCategoryLevel($value = ''){
			$str = '&nbsp;';
			$pace = "|";
			 $pace .= "----";
			$this->db->where('partners.bl_active <>',-1);
			$query =  $this->db->get('partners');
			$data= $query->result();
			 foreach($data as $object):
			  $str .= "<option value='".$object->partners_id."'".($object->partners_id==$value?" selected=\"selected\"":"").">" . $pace . $object->name. "</option>";
			 endforeach;
			return $str;
	 }    
    
  }
?>
